package dongshi.daddy.consumer;

import dongshi.daddy.api.UserRpcService;
import dongshi.daddy.api.dto.UserAddDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class UserRpcServiceTest03 implements CommandLineRunner {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Resource
    private UserRpcService userRpcService;

    @Override
    public void run(String... args) {
        // 添加用户
        try {
            // 创建 UserAddDTO
            UserAddDTO addDTO = new UserAddDTO();
            addDTO.setName("dongshidaddy"); // 设置为 dongshidaddy ，触发 ServiceException 异常
            addDTO.setGender(1);
            // 发起调用
            userRpcService.add(addDTO);
            logger.info("[run][发起一次 Dubbo RPC 请求，添加用户为({})]", addDTO);
        } catch (Exception e) {
            logger.error("[run][添加用户发生异常({})，信息为:[{}]", e.getClass().getSimpleName(), e.getMessage());
        }
    }

}
